/*********************************
* John Clayton
* Assignment 3
* CS362
* Village test
*********************************/

#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <math.h>

#define NUM_TESTS 10 //Number of times to run the test

int main(){
   int i, j, k, player, numPlayers, handPos, opt1, opt2, opt3,
       bonus = 1, currNumActs;
   int* handCounts;
   int* kCards;
   struct gameState *state;
   enum CARD card = village;
   enum CARD firstCard = curse;
   enum CARD lastCard = treasure_map;
   PlantSeeds(3);
   SelectStream(0);
   assert(state != 0);

   printf("Beginning testing card: village\n**************************************\n");
   for(i = 0; i <= NUM_TESTS; i++){
      state = newGame();
      numPlayers = (((int) (Random() * 1000))%4) + 1;
      handCounts = (int*)malloc(sizeof(int)*numPlayers);
      player = state->whoseTurn;
      for(j = 0; j < numPlayers; j++){
       memset(state->deck, 1, 5);
       memset(state->discard, 1, 5);
	state->handCount[j] = ((int) (Random() * 256)) % 54 + 7;
       for(k = 0; k < state->handCount[j]; k++);
	  state->hand[j][k] = ((int) (Random() * 256)) % (lastCard - firstCard) + firstCard;
	state->deckCount[j] = 5;
	state->discardCount[j] = 5;
       handCounts[j] = state->handCount[j];
      } 
      handPos = ((int) (Random() * 256)) % state->handCount[player];
      currNumActs = state->numActions;
      opt1 = (int) (Random() * 256) % (lastCard - firstCard) + firstCard;
      opt2 = (int) (Random() * 256) % (lastCard - firstCard) + firstCard;
      opt3 = (int) (Random() * 256) % (lastCard - firstCard) + firstCard;
      cardEffect(card, opt1, opt2, opt3, state, handPos, &bonus);
      if(state->handCount[player] != handCounts[player])
	 printf("[Test %d]The current player has wrong number of cards. (should have: %d, has: %d)\n", i, handCounts[player], state->handCount[player]);
      if(currNumActs + 2 != state->numActions)
	 printf("[Test %d]The current player has wrong number of actions. (should have: %d, has: %d)\n", i, currNumActs + 2, state->numActions);
   }
   printf("Ending testing card: village\n***********************************\n");
   return 0;
}
